#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

int main( int argc, char *argv[] ){

    if( argc != 2 ){
        printf("usage:\n%s tmp.bin\n", argv[0]);
        return 0;
    }

    char binfile[1024];
    
    sprintf(binfile, "%s", argv[1]);
    
    FILE *fb = fopen(binfile, "rb");
    
    int imax = 1250*100*5;
    int num = imax*4/2;
    uint16_t *regs = (uint16_t*)malloc(sizeof(uint16_t)*num);
    
    int num_chk = fread(regs, sizeof(uint16_t), num, fb);
    
    if( num_chk != num ){
    	printf("(%s:L:%d) Error in reading binary data: %s\n", __FILE__, __LINE__, binfile);
    	printf("@ num_chk = %d\n", num_chk);
    	printf("@ num     = %d\n", num);
    	exit(0);
    }
    
    fclose(fb);

    int i;
    // for( i=0; i<10000; i++ ){
    // for( i=0; i<num/4; i++ ){
/*
        uint16_t val0 = regs[i];
        uint16_t val = (val0&0xff<<8) + (val0>>8);
        printf("%6u %6d\n", val0, val); // 利用AD9249输出pattern，验证了regs[i]中取出的数据就是正常的结果，不需要额外经过endian转换
*/
        // printf("%6u\n", regs[i]);
    // }


    int tmp[32];
    int cnt=0;
    i=0;
    while( i<(num/5) ){
/*    while( i<1000 ){*/

        tmp[31-cnt] = regs[i];
        cnt++;
        i++;

        if( cnt >= 32 ){
            int j;
            for(j=0; j<32; j++){
                printf("%6d\n", tmp[j]);
            }
            cnt=0;
        }
    }

    free(regs);
}
